package com.example.demo.controller;

import java.util.List;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.bean.CmsLink;
import com.example.demo.common.Response;
import com.example.demo.service.CmsLinkService;

@RestController
@RequestMapping("/link")
public class CmsLinkController {
	
	private CmsLinkService cmsLinkService;
	
	@GetMapping("/selectAll")
	public Response<List<CmsLink>> selectAll() {
		List<CmsLink> list = cmsLinkService.selectAll();
		return Response.ok(list);
	}
	@PostMapping("/selectById")
	public Response<CmsLink> selectById(Integer id) {
		CmsLink cLink = cmsLinkService.selectById(id);
		return Response.ok(cLink);
	}
	@DeleteMapping("/deleteById")
	public Response<String> deleteById(Integer id) {
		int count = cmsLinkService.deleteById(id);
		if (count ==-1) {
			return Response.error("删除失败！！！");
		}
		return Response.ok("成功删除了"+count+"条链接信息！！！");
	}
	
	@DeleteMapping("/deleteByIds")
	public Response<String> deleteByIds(Integer[] ids)
	{
		int count = cmsLinkService.batchDeleteByIds(ids);
		if (count ==0) {
			return Response.error("删除失败！！！");
		}
		return Response.ok("成功删除"+count+"条链接信息！！！");
	}
	
	@PostMapping("/saveOrUpdate")
	public Response<String> saveOrUpdate(CmsLink cmsLink) {
	int count=	cmsLinkService.saveOrUpdate(cmsLink);
	if (count==-1) {
		return Response.error("保存失败！！！");
	}
		return Response.ok("保存成功");
	}
}








